<template>
    <div>

    </div>
</template>


<script>
import { mapGetters, mapActions } from "vuex";
import auth from "../../api/auth";
import Header from "../../components/Header/Header";
import Footer from "../../components/Footer/Footer";
export default {
    name: "index",
    components: {
        Header,
        Footer
    },
    data() {
        return {
            password: ''
        };
    },
    mounted() {
        console.log(this.$route)
        this.enterPass()
    },
    methods: {
        ...mapActions(["login", "checkLogin", "logout", "getPermissions"]),
        enterPass() {
            this.$prompt('请输入您需要重置的密码', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(async ({ value }) => {
                console.log(value)
                this.password = value
                this.confirmPass()
            }).catch(() => {
                
            });
        },
        confirmPass() {
            this.$prompt('请再次输入您的密码', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(async ({ value }) => {
                if (this.password == value) {
                    let res = await auth.restPassword({sid:decodeURIComponent(this.$route.query.sid), newPassword:this.$md5(value) })
                    console.log(res.errorMsg)
                    if (res.success) {
                        this.$message({
                            type: 'success',
                            message: '密码重置成功!'
                        });
                        setTimeout(()=>{
                               window.location.href = `http://${window.location.host}`
                        },1500)
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.errorMsg
                        });
                    }
                } else {
                    this.$message({
                        type: 'error',
                        message: '两次密码输入不一致!'
                    });
                    this.enterPass()
                }
            }).catch(() => {

            });
        }
    },
    computed: {
        ...mapGetters(["isLogin", "user"])
    }
};
</script>

<style scoped lang='scss'>
</style>
